c	Program Post_P
c
c	This program reads the output files from the CST Model
c	and processes them so that they can be plotted.  The
c	plotting software are TechPlot and Grapher.
c
c
	REAL LSECT1
c
	DIMENSION Hseries(150,150,200),SXseries(150,200),SYseries(150,200)
	. ,CSECT1(150,200),CSECT2(150,200),CSECT3(150,200),LSECT1(150,200),
	. HaveRA1(200),RelVol1(200),HaveRA2(200),RelVol2(200)
c

	OPEN(UNIT=1,file='POSTIN.DAT')
	 READ(1,*)
	 READ(1,*) ISECT1
	 READ(1,*)
	 READ(1,*) ISECT2
	 READ(1,*)
	 READ(1,*) ISECT3
	 READ(1,*)
	 READ(1,*) JSECT1
	 READ(1,*)
	 READ(1,6)ILRA1,IRRA1,JTRA1,JBRA1
    6	  FORMAT (4I10)
	 READ(1,*)
	 READ(1,6) ILRA2,IRRA2,JTRA2,JBRA2
	CLOSE (UNIT=1)
c
	OPEN(UNIT=1,file='CONTRL.DAT')
	 READ(1,*) IMAX,JMAX,NDATA,DELTAX,DELTAY,DT
	CLOSE(UNIT=1)
c
c	Read in the series of depth grids and shoreline cooridnates
c
	OPEN(UNIT=1,file='CSTMout.DAT')
	 DO 60 N=1,NDATA
	 DO 60 J=1,JMAX
   60	  READ(1,*)(Hseries(I,J,N),I=1,IMAX)
	 DO 65 N=1,NDATA
   65	  READ(1,*)(SXseries(I,N),SYseries(I,N),I=1,IMAX)
	CLOSE(UNIT=1)
c
c	Zero variable
c
	Htot=0.
c
c	If there is a Ref.Area then its right upper corner must be > 0
c
	 IF(IRRA1.GT.0)GOTO 80
c
   70	 IF(IRRA2.GT.0)GOTO 139
	GOTO 180
c
c	Determine the rel. volume & ave. depth of Ref.Area 1
c
   80	DO 130 N=1,NDATA
	DO 120 J=JBRA1,JTRA1
	DO 120 I=ILRA1,IRRA1
  120	 Htot=Hseries(I,J,N)+Htot
	 RelVol1(N)=Htot
  130	 HaveRA1(N)=Htot/(((float(IRRA1-ILRA1))*DELTAX)*
     . ((float(JTRA1-JBRA1))*DELTAY))
c
	GOTO 70
c
c	Determine the rel.volume & ave. depth of Ref.Area 2
c

  139	DO 150 N=1,NDATA
	DO 140 J=JBRA2,JTRA2
	DO 140 I=ILRA2,IRRA2
  140	 Htot=Hseries(I,J,N)+Htot
	 ReLVol2(N)=Htot
  150	 HaveRA2(N)=Htot/(((float(IRRA2-ILRA2))*DELTAX)*
     . ((float(JTRA2-JBRA2))*DELTAY))
c
  180  CONTINUE
c
c	Develop output of Cross shore Section 1
c
	 IF(ISECT1.EQ.0)GOTO 210
	DO 203 N=1,NDATA
	DO 203 J=1,JMAX
  203	 CSECT1(J,N)=Hseries(ISECT1,J,N)
c
c	Edit 'eroded' beds for CSECT1
c     If you set the value after NDATA-1,from 1 to 2 then
c      the original profile will show up
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c   COMMENTED IN BED EROSION - Comment out to see all lines
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c
cw	DO 205 N=NDATA-1,1,-1
cw	DO 205 J=1,JMAX
cw 205	 CSECT1(J,N)=MIN(CSECT1(J,N),CSECT1(J,N+1))
c
c	Output edited Cross shore Section 1
c

	 OPEN(UNIT=2,file='CSECT1.DAT')
	DO 207 N=1,NDATA
  	DO 206 J=1,JMAX
	  YYA=((float(J)*DELTAY)-(DELTAY/2.))
  206 WRITE(2,*)YYA,CSECT1(J,N)
  207 WRITE(2,*)
	 CLOSE(UNIT=2)
c
  210	 CONTINUE
c
c	shoreline evolution
	 OPEN(UNIT=2,file='SHLINE.DAT')
	DO 607 N=2,NDATA
  	DO 606 J=1,IMAX
  606 WRITE(2,*)SXseries(J,N),SYseries(J,N)
  607 WRITE(2,*)
	 CLOSE(UNIT=2)
c
  610	 CONTINUE
c
c	Develop output of Cross shore Section 2
c
	 IF(ISECT2.EQ.0)GOTO 220
	DO 213 N=1,NDATA
	DO 213 J=1,JMAX
  213	 CSECT2(J,N)=Hseries(ISECT2,J,N)
c
c	Edit 'eroded' beds for CSECT2
c     If you set the value after NDATA-1,from 1 to 2 then
c      the original profile will show up
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c   COMMENTED IN BED EROSION - Comment out to see all lines
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	DO 215 N=NDATA-1,2,-1
	DO 215 J=1,JMAX
 215	 CSECT2(J,N)=MIN(CSECT2(J,N),CSECT2(J,N-1))
c
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c
c	Output edited Cross shore Section 2
c

	OPEN(UNIT=2,file='CSECT2.DAT')
	DO 217 N=1,NDATA
  	DO 216 J=1,JMAX
	  YYA=((float(J)*DELTAY)-(DELTAY/2.))
  216 WRITE(2,*)YYA,CSECT2(J,N)
  217 WRITE(2,*)
	 CLOSE(UNIT=2)
c
  220	 CONTINUE
c
c	Develop output of Cross shore Section 3
c
 	 IF(ISECT3.EQ.0)GOTO 230
	DO 223 N=1,NDATA
	DO 223 J=1,JMAX
  223	 CSECT3(J,N)=Hseries(ISECT3,J,N)
c
c	Edit 'eroded' beds for CSECT3
c     If you set the value after NDATA-1,from 1 to 2 then
c      the original profile will show up
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c   COMMENTED IN BED EROSION - Comment out to see all lines
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	DO 225 N=NDATA-1,2,-1
	DO 225 J=1,JMAX
  225	 CSECT3(J,N)=MIN(CSECT3(J,N),CSECT3(J,N-1))
c
	OPEN(UNIT=2,file='CSECT3.DAT')
	 DO 227 N=1,NDATA
  	 DO 226 J=1,JMAX
	   YYA=((float(J)*DELTAY)-(DELTAY/2.))
c
c	Output edited Cross shore Section 3
c
  226  WRITE(2,*)YYA,CSECT3(J,N)
  227  WRITE(2,*)
	CLOSE(UNIT=2)
c
  230	 CONTINUE
c
c	Write time series for Rel.Areas 1 and 2
c
	 IF(IRRA1.EQ.0) GOTO 280
	OPEN(UNIT=2,file='RA1.DAT')
	 WRITE(2,*)(HaveRA1(N),RelVol1(N),N=1,NDATA)
	CLOSE(UNIT=2)
c
  280	 IF(IRRA1.EQ.0) GOTO 300
	OPEN(UNIT=2,file='RA2.DAT')
	 WRITE(2,*)(HaveRA2(N),RelVol2(N),N=1,NDATA)
	CLOSE(UNIT=2)
c
  300	 CONTINUE
c
c	Develop output of Longshore Section 1
c
	 IF (JSECT1.EQ.0)GOTO 348
	DO 342 N=1,NDATA
	DO 342 I=1,IMAX
  342	 LSECT1(I,N)=Hseries(I,JSECT1,N)
c
c	Edit 'eroded' beds for LSECT
c     If you set the value after NDATA-1,from 1 to 2 then
c      the original profile will show up
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c   COMMENTED IN BED EROSION - Comment out to see all lines
c   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	DO 343 N=NDATA-1,2,-1
	DO 343 I=1,IMAX
  343	 LSECT1(I,N)=MIN(LSECT1(I,N),LSECT1(I,N-1))
c
c	Output edited Longshore Section 1
c
	OPEN(UNIT=2,file='LSECT1.DAT')
	 DO 345 N=1,NDATA
	 DO 344 I=1,IMAX
	   XXA=(((float(I))*DELTAX)-(DELTAX/2.))
  344	 WRITE(2,*) XXA,LSECT1(I,N)
  345	 WRITE(2,*)
	CLOSE(UNIT=2)
c
  348	CONTINUE
c
c
c
	END